package com.xcity.game.combat.skill.impl;

import java.util.List;

import com.xcity.game.combat.Action;
import com.xcity.game.combat.ActionEffect;
import com.xcity.game.combat.attr.CombatAttributeType;
import com.xcity.game.combat.buff.CombatBuff;
import com.xcity.game.combat.skill.CombatSkill;
import com.xcity.game.combat.unit.CombatUnit;
import com.xcity.game.common.GameStaticConfig;
import com.xcity.game.skill.Skill;

/**
 * 云开雾散<br/>
 * 驱散所有人身上的异常状态，并恢复等同于自身血量{0}%的HP
 * @author yang.li
 *
 */
public class COMBAT_SKILL_90118 extends CombatSkill {

	public COMBAT_SKILL_90118(Skill skill) {
		super(skill);
	}

	@Override
	public void calcDamage(Action action) {
		CombatUnit source = action.unit;
		List<CombatUnit> units = source.getTeam().all();
		float rate = skill.getParameter(0) / GameStaticConfig.percentBase;
		for (int i = 0; i < units.size(); i++) {
			CombatUnit unit = units.get(i);
			if (!unit.isDied()) {
				List<CombatBuff> buffs = unit.getBuffs();
				for (int j = 0, size = buffs != null ? buffs.size() : 0; j < size; j++) {
					CombatBuff buff = buffs.get(j);
					if (buff.isDebuff() && buff.getState() != CombatBuff.STATE_REMOVED) {
						buff.uneffect();
						action.ref().addBuff(buff);
					}
				}
				
				ActionEffect eff = action.addTarget(unit);
				int hpDelta = Math.max((int) (unit.getHp() * rate), 1);
				eff.effect(CombatAttributeType.HP, hpDelta);
			}
		}
	}
	
}
